/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entityFacades;

import entities.Vehicle;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author wesleycl
 */
@Stateless
public class VehicleFacade implements VehicleFacadeLocal {
    @PersistenceContext(name="spssample-ejbPU")
    private EntityManager em;

    public void create(Vehicle vehicle) {
        em.persist(vehicle);
    }

    public void edit(Vehicle vehicle) {
        em.merge(vehicle);
    }

    public void remove(Vehicle vehicle) {
        em.remove(em.merge(vehicle));
    }

    public Vehicle find(Object id) {
        return em.find(Vehicle.class, id);
    }

    public List<Vehicle> findAll() {
        return em.createQuery("select object(o) from Vehicle as o").
                getResultList();
    }

}
